#include "types.h"
#include "stat.h"
#include "user.h"
#include "fcntl.h"

#define BP 10

int main( int argc, char *argv[] )
{
	int i, fd;
	if ( argc <= 1 )
	{
		printf( 1, "no argc\n" );
		exit();
	}
	int filenum = atoi( argv[1] );
	if ( filenum > 15 )
	{
		printf( 1, "to mach testfile\n" );
		exit();
	}

	printf( 1, "------test large file read------\n" );

	int	start, end;
	char	str[512];
	char	filename[100][3];
	for ( i = 0; i < filenum; i++ )
	{
		filename[i][0]	= i / 10 + '0';
		filename[i][1]	= i % 10 + '0';
		filename[i][2]	= '\0';
	}

	
    int time=0;
	for ( i = 0; i < filenum; i++ )
	{
        int rand = uptime()%filenum;

        if ( (fd = open( filename[rand], O_RDONLY ) ) < 0 )
		{
			printf( 1, "test: cannot open %s\n", filename[rand] );
			exit();
		}
    start = uptime();
		for ( int ii = 0; ii < BP; ii++ )
			read( fd, str, 512 );
    end = uptime();
    time+=end-start;
		sleep(13);
        close(fd);
	}

	

	printf( 1, "read time total: %d, avg: %d\n", time, (time) / filenum );

	exit();
}